<?php
require_once(LIB.'/datalistcp_index.class.php');
require_once(DEDEINC.'/enums.func.php');

class index extends Control{

    function index(){
        parent::__construct();
        $this->mwenda = $this->Model('mwenda');
        $this->mregister = $this->Model('mregister');
        $this->mcollegeinfo_detail = $this->Model("mcollegeinfo_detail");
    }

    function ac_index(){

        $sql = "select id,hit,title,isTop,isGood,updateTime from `#@__guanjun_wenda` order by isTop DESC,updateTime DESC,hit DESC";
        $dl = new DataListCP();
        $dl->pageSize = 10;              //设定每页显示记录数（默认25条）
        $dl->style='admin';
        $dl->SetTemplate(DEDEWENDA.'/templates/default/index.htm');      //载入模板
        $dl->SetSource($sql);            //设定查询SQL

        $dl->Display();
/*        $this->SetTemplate("index.htm");
        $this->Display();*/
    }

    function ac_register(){

        $adduser = request("adduser","");

        if(empty($adduser)){
            require_once(DEDEDATA.'/enums/area.php');
            $this->SetVar("schoolInfo",$em_areas);

            $this->SetTemplate("register.htm");
            $this->Display();
        }else{
            $email = request("email","");
            $password = md5(request("password",""));
            $realname = request("realname","");
            $tel = request("tel","");
            $graduatetime = request("graduatetime","");
            $lastschool = request("lastschool","");
            $degree = request("degree","");
            $yxxys = request("yxxys","");
            $addTime = $updateTime = date("Y-m-d H:i:s",time());
            //file_put_contents("/home/zsh/桌面/log.txt", $email . "--" . $realname . "--" . $tel . "--" . $graduatetime . "--" . $lastschool . "--" . $degree . "--" . $yxxys);
            if(empty($yxxys)){
                echo 1;
            }else{

            $this->mregister->register_query("insert into `#@__guanjun_register` (email,userName,phone,dateGraduate,schoolGraduate,education,schoolChoose,addTime,updateTime)
                values ('$email','$realname','$tel','$graduatetime','$lastschool','$degree','$yxxys','$addTime','$updateTime')");
            }
        }

    }

     function ac_get_wenda(){
        $id = intval(request("id",""));
        $where = "id = ".$id;

        //点击量
        $this->mwenda->wenda_query("update `#@__guanjun_wenda` set hit=hit+1 where " . $where);

        $data = $this->mwenda->wenda_get_one($where);
        echo json_encode(array("content" => $data['content'],"hit" => $data['hit']));
    }

    function ac_get_school(){ // 注册页根据地区id返回院校
        $area = request("school","");
        if($area == "请选择"){
            echo "";
        }else{
           $str = "";
    /*         for ($i=0; $i < 5; $i++) {
                $str .= '<li><a href="javascript:void(0);" onclick="add_school(' . ($id + $i)  . ',\'北京化工大学 ' . ($id + $i) . '\')" class="" id="a' . ($id + $i) . '">学校' . ($id + $i) . ' </a></li>';
            }*/
            $data =  $this->mcollegeinfo_detail->detail_get_list("`#@__collegeinfo`"," area=\"" .$area . "\"");
            foreach ($data as $value) {
                $str .= '<li><a href="javascript:void(0);" onclick="add_school(' . $value['collegeId']  . ',\'' . $value['name'] .  '\')" class="" id="a' . $value['collegeId'] . '">' . $value['name'] . ' </a></li>';
            }
            echo $str;
        }

    }

    function ac_check_mail(){ //查询填写的邮箱是否已经被注册  是返回1 否则返回0
            $email = request("email","");
            $where = "email=\"" . $email ."\"";
            $data = $this->mregister->register_get_one($where);
            if(!empty($data['email'])){
                echo 1;
            }else{
                echo 0;
            }

    }

}
?>